/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipo.mm.web.util.pager;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import org.ipo.mm.ejb.entities.Actions;
import org.ipo.mm.ejb.facade.actions.ActionsFacadeLocal;
import org.ipo.mm.web.util.ConstantManager;

/**
 *
 * @author makcro
 */
public class FinishedActionsPager extends ActionsPager{

    public FinishedActionsPager() {
        resultsTotal = lookupActionsFacade().getByStatusNotDeletedCount(ConstantManager.ACTION_STATUS_FINISHED);
    }

    @Override
    protected void injectData(HttpServletRequest request) {
        List<Actions> actoins = lookupActionsFacade().findByStatusNotDeleted(ConstantManager.ACTION_STATUS_FINISHED, firstResult, maxResultsPerPage);

        request.setAttribute("ACTIONS_SEARCH_RESULTS", actoins);
        request.setAttribute("ACTIONS_SEARCH_PAGENUMBERS", generatePageNumbers());
        request.setAttribute("ACTIONS_SEARCH_TOTAL_RESULTS", this.resultsTotal);
        request.setAttribute("ACTIONS_SEARCH_SHOW_NEXT", new Boolean(this.showNext));
        request.setAttribute("ACTIONS_SEARCH_SHOW_PREV", new Boolean(this.showPrev));
    }


    private ActionsFacadeLocal lookupActionsFacade() {
        try {
            Context c = new InitialContext();
            return (ActionsFacadeLocal) c.lookup("java:comp/env/ActionsFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }


}
